﻿
function modelChanged(column) {

    var modid = $('#modelCol' + column).val();
    $.ajax({
        url: "/AutoModel/ModelModificationPropertiesGet/" + modid,
        data: { data: 1 },
        success: function (data) {

            for (var i = 1; i < 100; i++) {
                $('#prop_' + column + '_' + i).html('');
            }


            if (data) {
                for (var key in data) {
                    var val = data[key];


                    $('#prop_' + column + '_' + val.Prop2).html(val.Prop3);

                }
            }

            if ($('#ShowDiffers').val() == "1") {
                showdiffs();
            }
        },
        error: function (data) {

        },
        type: "POST"
    });

    if ($('#ShowDiffers').val() == "1") {
        showdiffs();
    }
}


$(document).ready(function () {


    if ($("#modelCol1").val() != '0') {
        modelChanged('1');
    }

    if ($("#modelCol2").val() != '0') {
        modelChanged('2');
    }

    if ($("#modelCol3").val() != '0') {
        modelChanged('3');
    }

});


function showdiffs() {
    var propsId = $("#propS").val().split('_');


    if (propsId.length > 0) {
        for (var i = 1; i < propsId.length; i++) {
            // alert(propsId[i]);
            var col1 = $("#prop_1_" + propsId[i]).html();
            var col2 = $("#prop_2_" + propsId[i]).html();
            var col3 = $("#prop_3_" + propsId[i]).html();


            $("#td_prop_1_" + propsId[i]).css("background-color", "");
            $("#td_prop_2_" + propsId[i]).css("background-color", "");
            $("#td_prop_3_" + propsId[i]).css("background-color", "");

            if (col1 != "" && col2 != "" && col1 != col2) {
                $("#td_prop_1_" + propsId[i]).css("background-color", "lightcyan");
                $("#td_prop_2_" + propsId[i]).css("background-color", "lightcyan");
            }


            if (col1 != "" && col3 != "" && col1 != col3) {
                $("#td_prop_1_" + propsId[i]).css("background-color", "lightcyan");
                $("#td_prop_3_" + propsId[i]).css("background-color", "lightcyan");
            }


            if (col2 != "" && col3 != "" && col2 != col3) {
                $("#td_prop_2_" + propsId[i]).css("background-color", "lightcyan");
                $("#td_prop_3_" + propsId[i]).css("background-color", "lightcyan");
            }
        }
    }

    return false;
}


function turnOffFunction() {

    $('#ShowDiffers').val("0");
    var propsId = $("#propS").val().split('_');

    if (propsId.length > 0) {
        for (var i = 1; i < propsId.length; i++) {
            $("#td_prop_1_" + propsId[i]).css("background-color", "");
            $("#td_prop_2_" + propsId[i]).css("background-color", "");
            $("#td_prop_3_" + propsId[i]).css("background-color", "");
        }
    }
    $("#tOff").removeClass("button_1");
    $("#tOff").removeClass("active");
    $("#tOff").addClass("button_2");

    $("#tOn").addClass("button_1");
    $("#tOn").addClass("active");
    $("#tOn").removeClass("button_2");
  

    return false;
}


function turnOnFunction() {
    $('#ShowDiffers').val("1");

   

    $("#tOff").addClass("button_1");
    $("#tOff").addClass("active");
    $("#tOff").removeClass("button_2");

    $("#tOn").removeClass("button_1");
    $("#tOn").removeClass("active");
    $("#tOn").addClass("button_2");

    showdiffs();
}